package com.twu.biblioteca;

import java.util.ArrayList;

/**
 * Created by thais on 1/13/14.
 */
public class Manager {

    private ArrayList<Book> books;
    private ArrayList<Movie> movies;
    private ArrayList<Customer> customers;


    public Manager(){
        books = new ArrayList<Book>();
        movies = new ArrayList<Movie>();
        customers = new ArrayList<Customer>();
    }

    public void add(Book book){
        this.books.add(book);
    }

    public void add(Movie movie) {
        this.movies.add(movie);
    }

    public void add(Customer customer){
        this.customers.add(customer);
    }

    public ArrayList<Book> getAllBooks() {
        return this.books;
    }

    public String sayHello() {
        return "Welcome Customer";
    }

    public ArrayList<Book> getAllAvailableBooks() {
        ArrayList<Book> availableBooks = new ArrayList<Book>();
        for (Book book: this.books){
            if(book.isAvailable()){
                availableBooks.add(book);
            }
        }
        return availableBooks;
    }

    public boolean checkoutBook(String book) {

        for(Book b: this.getAllAvailableBooks()){
            if(b.getName().equals(book)){
                b.setAvailable(false);
                return true;
            }
        }
        return false;
    }

    public boolean returnTheBook(String book) {
        for(Book b: this.getAllAvailableBooks()){
            if(b.getName().equals(book)){
                b.setAvailable(true);
                return true;
            }
        }
        return false;
    }


    public ArrayList<Movie> getAllAvailableMovies() {
        ArrayList<Movie> availableMovies = new ArrayList<Movie>();
        for (Movie movie: this.movies){
            if(movie.isAvailable()){
                availableMovies.add(movie);
            }
        }
        return availableMovies;
    }

    public boolean checkoutMovie(String movie) {
        for(Movie m: this.getAllAvailableMovies()){
            if(m.getName().equals(movie)){
                m.setAvailable(false);
                return true;
            }
        }
        return false;
    }


//    public boolean checkout(String name, String type) {
//        for(Item m: this.getAllAvailableMovies()){
//            if(m.getName().equals(movie)){
//                m.setAvailable(false);
//                return true;
//            }
//        }
//        return false;
//    }



    public ArrayList<Customer> getAllCustomers() {
        return this.customers;
    }

    public boolean loginCustomer(String email, String password) {
        for(Customer customer: this.getAllCustomers()){
            if(customer.getEmail().equals(email) && customer.getPassword().equals(password)){
                return true;
            }
        }
        return false;
    }

    public String returnAllCustomerInfo(Customer customer) {
        if(this.loginCustomer(customer.getEmail(),customer.getPassword())){
            return customer.toString();
        }
        else{
            return "Access Denied";
        }
    }
}
